
<?php
include 'select.php';
session_start();

if(isset($_SESSION['logined']) && $_SESSION['logined']){
   //$_SESSION['logined']有设置，并且值为真，表示已经登录
   //echo "当前登录用户是: ".$_SESSION['name'];
}else{
  echo "<script> alert('你还没有登录，请登录！');parent.location.href='/920/login.php'; </script>";
}
if( isset($_POST['renewpass'])){
     
     $renewpass = $_POST['renewpass'];
     $mpass = $_POST['mpass'];
     //连接数据库
     $_SESSION['logined']=1;   //判断是否已经登录的依据。
   
     $conn = new mysqli($servername, $username, $password, $dbname);
 if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
 }
 //验证内容是否与数据库的记录吻合。
 $name = $_SESSION['name'];


 $sql = "UPDATE user SET password='$renewpass' WHERE user='$name' AND password='$mpass'";//update user set password='123' where user='1'
 //执行上面的sql语句并将结果集赋给result。


 $result = $conn->query($sql);


 //判断结果集的记录数是否大于0
 if ($result) {
      $_SESSION['user_account'] = $name;
      // 输出每行数据

            echo "<script> alert('修改成功');parent.location.href='/920/index.php'; </script>"; 
            
     } else {
          echo "<script> alert('修改失败');parent.location.href='/920/index.php'; </script>"; 
     }
     $conn->close();  
    
     }

?>

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title> - 素材牛模板演示</title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head"><strong><span class="icon-key"></span> 修改会员密码</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" >
      <div class="form-group">
        <div class="label">
          <label for="sitename">管理员帐号：</label>
        </div>
        <div class="field">
          <label style="line-height:33px;">
           <?php echo $_SESSION['name'] ?>
          </label>
        </div>
      </div>      
      <div class="form-group">
        <div class="label">
          <label for="sitename">原始密码：</label>
        </div>
        <div class="field">
          <input type="password" class="input w50" id="mpass" name="mpass" size="50" placeholder="请输入原始密码" data-validate="required:请输入原始密码" />       
        </div>
      </div>      
      <div class="form-group">
        <div class="label">
          <label for="sitename">新密码：</label>
        </div>
        <div class="field">
          <input type="password" class="input w50" name="newpass" size="50" placeholder="请输入新密码" data-validate="required:请输入新密码,length#>=3:新密码不能小于3位" />         
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label for="sitename">确认新密码：</label>
        </div>
        <div class="field">
          <input type="password" class="input w50" name="renewpass" size="50" placeholder="请再次输入新密码" data-validate="required:请再次输入新密码,repeat#newpass:两次输入的密码不一致" />          
        </div>
      </div>
      
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>   
        </div>
      </div>      
    </form>
  </div>
</div>
</body></html>